import { registerApplication, start } from 'single-spa'

async function loadScript(url) {
  return new Promise((resolve, reject) => {
    let script = document.createElement('script')
    script.src = url
    script.onload = resolve
    script.onerror = reject
    document.head.appendChild(script)
  })
}

registerApplication({
  name: 'myVueApp',
  app: async () => {
    console.log('加载子应用')
    await loadScript(`http://localhost:10005/js/chunk-vendors.js`)
    await loadScript(`http://localhost:10005/js/app.js`)
    return window.singleVue
  },
  activeWhen: '/activity',
})
start()
